define(function (require, exports, module) {
	
	var CommentAnnotToolHandler = require("./CommentAnnotToolHandler.js");
	var CommentAnnotHandler = require("./CommentAnnotHandler.js");
	require("./AnnotHandleManager.js");
	FXREADER.CommentAnnotPlugin = function (pReaderApp,annotPlugin) {
        var    _pReaderApp = pReaderApp,
        	   _pAnnotPlugin = annotPlugin,
              _Language = _pReaderApp.GetLanguage(),
        	  _annotHandlerArray = [],
              _self = this;

        //获取Plugin名称;
        this.GetPluginName = function () {
            return "CommentAnnot";
        };
        //插件被注册的时候调用;
        this.PIOnRegister = function () {
           
        };
        //模块初始化;
        this.PIInit = function () {
        	
        	
        	var pUnderlineAnnotHandler = new CommentAnnotToolHandler(FXREADER.PDFData.CommentAnnotType.COMMENTTYPE_UNDERLINE,_pAnnotPlugin);
        	_pReaderApp.RegisterToolHandler(pUnderlineAnnotHandler);
        	var pHighlightAnnotHandler = new CommentAnnotToolHandler(FXREADER.PDFData.CommentAnnotType.COMMENTTYPE_HIGHLIGHT,_pAnnotPlugin);
        	_pReaderApp.RegisterToolHandler(pHighlightAnnotHandler);
        	
        	//Add Annotation handler
        	var pAnnotHandler = null;
        	pAnnotHandler = new CommentAnnotHandler(_pReaderApp , FXREADER.PDFData.CommentAnnotType.COMMENTTYPE_UNDERLINE , "Underline tool",_self);
        	_pAnnotPlugin.RegisterAnnotHandler(pAnnotHandler);
        	_annotHandlerArray.push(pAnnotHandler);

        	pAnnotHandler = new CommentAnnotHandler(_pReaderApp , FXREADER.PDFData.CommentAnnotType.COMMENTTYPE_HIGHLIGHT , "Highlight tool",_self);
        	_pAnnotPlugin.RegisterAnnotHandler(pAnnotHandler);
        	_annotHandlerArray.push(pAnnotHandler);
        	
            _self.CreateCmdAndBtn();
        };
        //模块卸载;
        this.PIUnload = function () {
        };

        this.GetReaderApp = function () {
            return _pReaderApp;
        };
        
        this.IsCommentsType = function(sType)
        {
        	if (sType == FXREADER.PDFData.CommentAnnotType.COMMENTTYPE_UNDERLINE ||
        		sType == FXREADER.PDFData.CommentAnnotType.COMMENTTYPE_HIGHLIGHT /*||
        		sType == FXREADER.PDFData.CommentAnnotType.COMMENTTYPE_SQUIGGLY ||
        		sType == FXREADER.PDFData.CommentAnnotType.COMMENTTYPE_STRIKEOUT ||
        		sType == FXREADER.PDFData.CommentAnnotType.COMMENTTYPE_CARET ||
        		sType == FXREADER.PDFData.CommentAnnotType.COMMENTTYPE_REPLACE*/)
        		return true;
        	else
        		return false;
        };
        
        this.CreateCmdAndBtn = function () {
        	//创建按钮
            _pReaderApp.AddCommandUI({
                UIName: "HighlightAnnot",
                CommandName: 'HighlightAnnotCommand',
                State: false,
                CreateHtmlContentFunc: function () {
                    return "<a id='HighlightAnnot' class='fwr_toolbar_btn fwr_toobar_handtool_dis fwr_toobar_image_btn' title='Highlight Text' style='margin-right:2px;' cmd='" + "HighlightAnnotCommand" + "'></a>";
                },
                OnCommandStateChange: function (data) {
                	if(data.state == false)
                	{
                		FXREADER.Common.UpdateBtnState("HighlightAnnot", "fwr_toobar_handtool_dis", "fwr_toobar_handtool_active", true);
                	}
                	else
                	{
                		FXREADER.Common.UpdateBtnState("HighlightAnnot", "fwr_toobar_handtool_active", "fwr_toobar_handtool_dis", true);
                	}
                },
                Init: function () {
                }
            });
            
            _pReaderApp.AddCommandUI({
                UIName: "UnderlineAnnot",
                CommandName: 'UnderlineAnnotCommand',
                State: false,
                CreateHtmlContentFunc: function () {
                    return "<a id='UnderlineAnnot' class='fwr_toolbar_btn fwr_toobar_handtool_dis fwr_toobar_image_btn' title='Underline Text' style='margin-right:2px;' cmd='" + "UnderlineAnnotCommand" + "'></a>";
                },
                OnCommandStateChange: function (data) {
                	if(data.state == false)
                	{
                		FXREADER.Common.UpdateBtnState("UnderlineAnnot", "fwr_toobar_handtool_dis", "fwr_toobar_handtool_active", true);
                	}
                	else
                	{
                		FXREADER.Common.UpdateBtnState("UnderlineAnnot", "fwr_toobar_handtool_active", "fwr_toobar_handtool_dis", true);
                	}
                },
                Init: function () {
                }
            });
        };
        
        _pReaderApp.AddCommand({
            state: true,
            name: "HighlightAnnotCommand",
            exec: function (data) {
                var curTool = _pReaderApp.GetCurToolHandler();
                var highlightTool = _pReaderApp.GetToolHandlerByName(FXREADER.PDFData.CommentAnnotType.COMMENTTYPE_HIGHLIGHT);
                if (highlightTool != curTool && highlightTool != null) {
                    _pReaderApp.SetCurToolHandler(highlightTool);
                } 

            }
        });

        _pReaderApp.AddCommand({
            state: true,
            name: "UnderlineAnnotCommand",
            exec: function (data) {
                var curTool = _pReaderApp.GetCurToolHandler();
                var underlineTool = _pReaderApp.GetToolHandlerByName(FXREADER.PDFData.CommentAnnotType.COMMENTTYPE_UNDERLINE);
                if (underlineTool != curTool && underlineTool != null) {
                    _pReaderApp.SetCurToolHandler(underlineTool);
                } 
            }
        });

    };

    exports.Reader_CreatePlugin = function (pReaderApp) {
    	var annotPlugin = pReaderApp.GetPluginByName(FXREADER.BASEANNOT_PLUGIN_NAME);
        var pCommentAnnotPlugin = new FXREADER.CommentAnnotPlugin(pReaderApp,annotPlugin);
        return pCommentAnnotPlugin;
    };
	
});